import { defineStore } from "pinia";
import Cookie from "js-cookie";
import router from "@/router";
export const adminStore = defineStore({
    id: 'adminStore',
    persist: {//数据持久化
        key: 'userInfo', // 自定义key
        storage: sessionStorage  // 自定义存储方式
    },
    state: () => ({
        user: new UserInfo(),//用户信息user:UserInfo
        loginInfo:{
            password:'',
            username:''
        }
    }),
    actions: {
        outLogin() {
            Cookie.remove('token')
            this.user=new UserInfo()
            router.replace('/login')
        }
    }
})
class UserInfo {
    avatarUrl?: string;
    gmtCreate: number;
    gmtLastLogin: string;
    id: number;
    lastLoginIp: string;
    perms: string[];
    phone: string;
    realname: string;
    roleIds: number[];
    roles: string[];
    status: number;
    username: string;
    constructor() {
        this.avatarUrl = '';
        this.gmtCreate = 0;
        this.gmtLastLogin = '';
        this.id = 0;
        this.lastLoginIp = '';
        this.perms = [];
        this.phone = '';
        this.realname = '';
        this.roleIds = [];
        this.roles = [];
        this.status = 0;
        this.username = '';
    }
}